package com.grass.p019lv.novel.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.novel.SearchNovelHotRecommendBean;
import com.androidx.p013lv.base.dialog.ProgressBarDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.google.android.material.tabs.TabLayout;
import com.grass.p019lv.bean.ClassFictionBean;
import com.grass.p019lv.databinding.FragmentFictionBinding;
import com.grass.p019lv.novel.activity.FictionFilterActivity;
import com.grass.p019lv.novel.activity.SearchNovelActivity;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.novel.fragment.FictionFragment */
public class FictionFragment extends LazyFragment<FragmentFictionBinding> implements View.OnClickListener {
    String HTTP_TAG = "classifyList";
    MyAdapterTab adapter;
    int classifyIdEd;
    List<LazyFragment> fragmentList;
    private ProgressBarDialog loading;
    List<ClassFictionBean> strings;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_fiction;
    }

    public static FictionFragment newInstance() {
        Bundle bundle = new Bundle();
        FictionFragment fictionFragment = new FictionFragment();
        fictionFragment.setArguments(bundle);
        return fictionFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ProgressBarDialog progressBarDialog = new ProgressBarDialog(getActivity());
        this.loading = progressBarDialog;
        progressBarDialog.setHint("拚命載入中...");
        this.loading.show();
        getInfo();
        ((FragmentFictionBinding) this.binding).llBtnFilter.setOnClickListener(this);
        ((FragmentFictionBinding) this.binding).llSearchNovel.setOnClickListener(this);
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (!NetUtil.isNetworkAvailable()) {
            ToastUtils.getInstance().showWeak("網路異常");
            return;
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getFictionClassList(1), new HttpCallback<BaseRes<List<ClassFictionBean>>>(this.HTTP_TAG) {
            /* class com.grass.p019lv.novel.fragment.FictionFragment.C31811 */

            public void onLvSuccess(BaseRes<List<ClassFictionBean>> baseRes) {
                if (baseRes.getData() == null || baseRes.getData().size() <= 0) {
                    ToastUtils.getInstance().showWeak("網路異常,請稍後再試");
                } else {
                    List<ClassFictionBean> data = baseRes.getData();
                    data.add(0, new ClassFictionBean(7, "全部"));
                    FictionFragment.this.setViewPager(data);
                }
                if (FictionFragment.this.loading != null && FictionFragment.this.loading.isShowing()) {
                    FictionFragment.this.loading.dismiss();
                }
            }
        });
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getNovelHotSearch(1, 30), new HttpCallback<BaseRes<SearchNovelHotRecommendBean>>("queryHotSearch") {
            /* class com.grass.p019lv.novel.fragment.FictionFragment.C31822 */

            public void onLvSuccess(BaseRes<SearchNovelHotRecommendBean> baseRes) {
                if (baseRes.getCode() != 200) {
                    Log.e("...", "出错");
                } else if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                    ((FragmentFictionBinding) FictionFragment.this.binding).tvScrollTextView.setList(baseRes.getData().getData());
                    ((FragmentFictionBinding) FictionFragment.this.binding).tvScrollTextView.startScroll();
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setViewPager(List<ClassFictionBean> list) {
        this.fragmentList = new ArrayList();
        this.strings = list;
        for (int i = 0; i < this.strings.size(); i++) {
            ClassFictionBean classFictionBean = this.strings.get(i);
            if (i == 0) {
                this.fragmentList.add(ClassFictionFragment.newInstance(0));
            } else {
                this.fragmentList.add(ClassFictionFragment.newInstance(classFictionBean.getClassId()));
            }
            if (i == 0) {
                this.classifyIdEd = classFictionBean.getClassId();
            }
        }
        this.adapter = new MyAdapterTab(this.fragmentList, this.strings, getChildFragmentManager(), 1);
        ((FragmentFictionBinding) this.binding).viewPager.setAdapter(this.adapter);
        ((FragmentFictionBinding) this.binding).viewPager.setOffscreenPageLimit(list.size());
        ((FragmentFictionBinding) this.binding).tabLayout.addOnTabSelectedListener((TabLayout.OnTabSelectedListener) new TabLayout.OnTabSelectedListener() {
            /* class com.grass.p019lv.novel.fragment.FictionFragment.C31833 */

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabReselected(TabLayout.Tab tab) {
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabSelected(TabLayout.Tab tab) {
                FictionFragment.this.changeTabTextView(tab, true);
                FictionFragment fictionFragment = FictionFragment.this;
                fictionFragment.classifyIdEd = fictionFragment.strings.get(tab.getPosition()).getClassId();
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabUnselected(TabLayout.Tab tab) {
                FictionFragment.this.changeTabTextView(tab, false);
            }
        });
        ((FragmentFictionBinding) this.binding).tabLayout.setupWithViewPager(((FragmentFictionBinding) this.binding).viewPager);
        if (((FragmentFictionBinding) this.binding).tabLayout.getTabCount() >= 2) {
            for (int i2 = 1; i2 < ((FragmentFictionBinding) this.binding).tabLayout.getTabCount(); i2++) {
                changeTabTextView(((FragmentFictionBinding) this.binding).tabLayout.getTabAt(i2), false);
            }
        }
    }

    public void onClick(View view) {
        if (!isOnClick()) {
            if (view.getId() == R.id.ll_btn_filter) {
                getActivity().startActivity(new Intent(getActivity(), FictionFilterActivity.class));
            }
            if (view.getId() == R.id.ll_search_novel) {
                getActivity().startActivity(new Intent(getActivity(), SearchNovelActivity.class));
            }
        }
    }

    public void changeTabTextView(TabLayout.Tab tab, boolean z) {
        if (tab.getCustomView() == null) {
            tab.setCustomView(R.layout.tab_layout_text_invention);
        }
        TextView textView = (TextView) tab.getCustomView().findViewById(16908308);
        if (z) {
            textView.setTextAppearance(getContext(), R.style.TabLayoutBoldTextSizes);
        } else {
            textView.setTextAppearance(getContext(), R.style.TabLayoutNormalTextSize);
        }
    }

    /* renamed from: com.grass.lv.novel.fragment.FictionFragment$MyAdapterTab */
    public class MyAdapterTab extends FragmentStatePagerAdapter {
        List<LazyFragment> fragmentList;
        List<ClassFictionBean> titleList;

        public MyAdapterTab(List<LazyFragment> list, List<ClassFictionBean> list2, FragmentManager fragmentManager, int i) {
            super(fragmentManager, i);
            this.fragmentList = list;
            this.titleList = list2;
        }

        @Override // androidx.fragment.app.FragmentStatePagerAdapter
        public Fragment getItem(int i) {
            return this.fragmentList.get(i);
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public int getCount() {
            return this.fragmentList.size();
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public CharSequence getPageTitle(int i) {
            return this.titleList.get(i).getTitle();
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
    }
}
